package com.xstablet.util;

import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xstablet.R;
import com.zyyoona7.popup.EasyPopup;

/**
 * Created by Administrator on 2020/7/15 0015.
 */

public class AskChoosePopupUtil implements View.OnClickListener {


    private Activity activity;

    public AskChoosePopupUtil(Activity activity) {

        this.activity = activity;

        initPopuPopu();
    }

    private EasyPopup popu;

    private void initPopuPopu() {
        popu = EasyPopup.create()
                .setContext(activity)
                .setContentView(R.layout.popup_askchoose)
                .setWidth(WindowManager.LayoutParams.FILL_PARENT)
                .setHeight(WindowManager.LayoutParams.FILL_PARENT)
                .setOnViewListener(new EasyPopup.OnViewListener() {
                    @Override
                    public void initViews(View view, EasyPopup basePopup) {

                        initView(view);
                    }

                })
                .setFocusAndOutsideEnable(true)
                .apply();

    }

    private LinearLayout linGrade, linSubj;
    private TextView tvGrade, tvSubj, tvSure;
    private ImageView ivGrade, ivSubj;

    private void initView(View view) {

        linGrade = view.findViewById(R.id.lin_grade);
        tvGrade = view.findViewById(R.id.tv_grade);
        ivGrade = view.findViewById(R.id.iv_grade);

        linSubj = view.findViewById(R.id.lin_subj);
        tvSubj = view.findViewById(R.id.tv_subj);
        ivSubj = view.findViewById(R.id.iv_subj);

        tvSure = view.findViewById(R.id.tv_sure);

        linGrade.setOnClickListener(this);
        ivGrade.setOnClickListener(this);
        linSubj.setOnClickListener(this);
        ivSubj.setOnClickListener(this);
        tvSure.setOnClickListener(this);

    }


    public void dismiss() {
        popu.dismiss();
    }


    public void showAnswerPopuPopu(View view) {
        popu.showAtLocation(view, Gravity.CENTER, 0, 0);

    }


    @Override
    public void onClick(View v) {

        int i = v.getId();
        if (i == R.id.lin_grade) {

            if (listener != null) {
                listener.onChooseGrade();
            }
        } else if (i == R.id.iv_grade) {
            if (listener != null) {
                listener.onChooseGrade();
            }
        } else if (i == R.id.lin_subj) {

            if (listener != null) {
                listener.onChooseSubj();
            }
        } else if (i == R.id.iv_subj) {

            if (listener != null) {
                listener.onChooseSubj();
            }
        } else if (i == R.id.tv_sure) {

            if (listener != null) {
                listener.onSureChoose();
            }
        }
    }

    public interface ChooseAskListener {

        void onChooseGrade();

        void onChooseSubj();

        void onSureChoose();

    }

    public ChooseAskListener listener;

    public void setChooseAskListener(ChooseAskListener chooseAskListener) {

        this.listener = chooseAskListener;

    }
}
